package com.project.controller;

import com.project.bean.UserBean;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("users")
public class UserController {
    @Autowired
    private IUserService service;
    @RequestMapping("logins")
    public String log(String userName, String pwd, HttpServletRequest req){
       UserBean user =  service.login(userName,pwd);
       if(user != null){
           req.getSession().setAttribute("logUser",user);
           return "ok";
       }
       return "no";
    }
    @RequestMapping("getSessionUser")
    public UserBean getSessionUser(HttpServletRequest req){
        return (UserBean)req.getSession().getAttribute("logUser");
    }
}
